<?php //2017-07-01

/**
* 
*/
class NewCode
{	
	public $setarr = array(
		'lenght' => 3,
		'width' => 200,
		'height' => 100,
		'point' => 0,
		'line' => 0,
		'size' => 30,
		);
	public $src;
	function __construct($arrname=array())
	{	
		$this->setarr = array_merge($this->setarr,$arrname);
		//var_dump($this->setarr);
		
	}

	public function __get($key)
	{
		return $this->setarr[$key];
	}
	
	public function show($value=true)
	{
		if ($value) header("Content-type: image/jpeg");
		$this->_createImg();
		$this->_text();
		$this->_point();
		$this->_line();
		$this->_outPut();

	}

	public function _createImg()
	{
		$this->src = imagecreatetruecolor($this->width, $this->height);
		$color = imagecolorallocate($this->src, 0,0,0);
		imageFill($this->src,0,0,$color);
	}

	public function _text()
	{
		for ($i=0; $i < $this->lenght ; $i++) { 
			$w = $i*($this->width/$this->lenght);
			$w+= 25;
			$texts = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
			$text = $texts[mt_rand(0,strlen($texts)-1)];
			$color2 = imagecolorallocate($this->src,mt_rand(20,255),mt_rand(20,255),mt_rand(20,255));
			imagettftext($this->src, $this->size, mt_rand(-20,20), $w, mt_rand($this->height/2+$this->size/2,$this->height/2+$this->size/2+10), $color2, './FireBlock.ttf', $text);
		}
	}

	public function _point()
	{
		for ($i=0; $i < $this->point ; $i++) {
			$color2 = imagecolorallocate($this->src,mt_rand(20,255),mt_rand(20,255),mt_rand(20,255));
			imagesetpixel($this->src, mt_rand(0,$this->width),mt_rand(0,$this->height), $color2);
		}
	}

	public function _line()
	{
		for ($i=0; $i < $this->line ; $i++) { //随机生成线条前面两个控制上部分 后两控下
			$color2 = imagecolorallocate($this->src,mt_rand(20,255),mt_rand(20,255),mt_rand(20,255));
			imageline($this->src, mt_rand(15,$this->width-15), mt_rand($this->height/6,$this->height/2), mt_rand(15,$this->width-15), mt_rand($this->height/2+$this->height/6,$this->height/2+$this->height/4), $color2);
		}
	}

	public function _outPut()
	{	
	
		imagejpeg($this->src);

	}
}





$setarr = array(
		'lenght' => 4,
		'width' => 350,
		'height' => 150,
		'point' => 500,
		'line' => 15,
		'size' => 60,
		);

$obj = new NewCode($setarr);
$obj->show();


 ?>